package com.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import com.demo.livemanagement.livedelayqueue.LiveDelayTimeoutThread;
import com.demo.livemanagement.timertask.LiveTimeoutThreadTimerTask;

@SpringBootApplication
// 可以在这里扫描mapper接口
// @MapperScan("com.demo.mybatis.mapper") 也可以在mapper接口添加@mappper注解
// 扫描servlet
@ServletComponentScan
// 扫描定时器
@EnableScheduling
@EnableTransactionManagement // 开启事务,总开关不打开事务也可以回滚，亲测，不明原因
// @EnableAspectJAutoProxy //开启切面编程
// @EnableCaching//开启缓存
public class ApplicationMain {

	public static void main(String[] args) {

		SpringApplication application = new SpringApplication(ApplicationMain.class);
		// 注册EventListener，也可以通过注解注册@component
		// application.addListeners(new ApplicationReadyListener());
		// application.addListeners(new WebApplicationStartedEventListener());
		application.run(args);

		// SpringApplication.run(ApplicationMain.class, args);

		// 关闭热重启（这样做仍然可以初始化重启classloader，但是它不会监视文件的变化）
		// System.setProperty("spring.devtools.restart.enabled","false");

		// 启动Queue处理线程
		LiveTimeoutThreadTimerTask t1 = new LiveTimeoutThreadTimerTask();
		for (int i = 0; i < 1; i++) {
			Thread t = new Thread(t1);
			t.setName("====Live Queue handle thread" + i + "====");
			t.start();
		}
		// 启动DelayQueue处理线程
		LiveDelayTimeoutThread t2 = new LiveDelayTimeoutThread();
		for (int i = 0; i < 1; i++) {
			Thread t = new Thread(t2);
			t.setName("====Live DelayQueue handle thread" + i + "====");
			t.start();
		}
	}

}
